package com.twu.biblioteca;

/**
 * Created with IntelliJ IDEA.
 * User: PREETHI
 * Date: 26/5/13
 * Time: 3:43 PM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
public class LibraryManager {
     Scanner scan=new Scanner(System.in);
    private bookList booklist;
    private BookManager bookMan;
    private movieList movielist;
    private MovieManager movieMan;
    private int index;

    private UserAccountManager userMan;
    private user  loggedInUser;
    public LibraryManager() {
        movielist = new movieList();
        movieMan = new MovieManager(movielist);
        userMan=new UserAccountManager(loggedInUser);
        booklist = new bookList();
        bookMan = new BookManager(booklist);

    }

    public void displayMenus()
    {
        System.out.println("1.View all books\n" +
                "2.Reserve books\n" +
                 "3.View all movies\n"+
                 "4.Reserve movies\n"+
                  "5.Login\n"+    "6.Logout\n"+            "7.View Membership Details\n" +
                "8.Exit\n");

        System.out.println("SELECT AN OPTION:");
    }

    public void readIndex()
    {
        if(scan.hasNextInt() )
        index   =scan.nextInt();
        else index=-1;

   }
    public int getIndex()
    {
        return index;
    }

    public void runApp() {
        System.out.println(MESSAGES.WELCOME_MESSAGE);
        do {

              displayMenus();
              readIndex();
              respond(getIndex());

           } while(getIndex()!=8&&getIndex()!=-1);

    }

    public  void respond(int i) {
           if(i==1||i==2)
               bookMan.respond(index,loggedInUser);
            else if(i==3 ||i==4)
               movieMan.respond(index,loggedInUser);
            else if(i==5||i==6||i==7)
               loggedInUser= userMan.respond(index);
             else if(i==8)
                System.exit(0);

             else
               System.out.println(MESSAGES.INVALID_OPTION)   ;


    }



}
